package com.book.service.impl;

import com.book.mapper.UserMapper;
import com.book.service.UserService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author zzw2000
 * @Date 2022年08月28日 11:51
 * @Description 描述
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void update(Integer id, String password) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String pwd = encoder.encode(password);
        userMapper.update(id, pwd);
    }

    @Transactional
    @Override
    public void updateStu(Integer sid, Integer uid, String sex, Integer grade, String password) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String pwd = encoder.encode(password);
        userMapper.updateUser(uid, pwd);
        userMapper.updateStu(sid,sex,grade);
    }
}
